package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.ChildAssessInsertRequestDTO;
import com.example.child_protection.dto.request.find.ChildAssessRequestDTO;
import com.example.child_protection.dto.request.update.ChildAssessUpdateRequestDTO;
import com.example.child_protection.dto.response.ChildAssessListResponseDTO;
import com.example.child_protection.dto.response.ChildAssessResponseDTO;
import com.example.child_protection.service.ChildAssessManageService;
import com.example.child_protection.service.ChildAssessQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 儿童高危管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("childAssess")
@Api(value = "/api-childAssess", description = "儿童高危管理")
public class ChildAssessController extends BaseController {

    @Autowired
    public ChildAssessManageService childAssessManageService;

    @Autowired
    public ChildAssessQueryService childAssessQueryService;

    @ApiOperation(value ="查询儿童高危", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public ChildAssessResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        ChildAssessResponseDTO responseDTO = childAssessQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询儿童高危列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public ChildAssessListResponseDTO findList(ChildAssessRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        ChildAssessListResponseDTO responseDTO = childAssessQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加儿童高危", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(ChildAssessInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = childAssessManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改儿童高危", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(ChildAssessUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        requestDTO.setCreatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = childAssessManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除儿童高危", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = childAssessManageService.delete(requestDTO);
        return responseDTO;
    }

}
